home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / disk13.com / DISK13IO.DOC < prev    next >
Encoding:
Text File  |  1988-11-01  |  13.7 KB  |  351 lines

  1.  
  2.    Program:     DISK13IO.TPU
  3.  
  4.    Description: Sector I/O (Interrupt $13) Unit for Turbo Pascal 5.0
  5.  
  6.    Author:      Kurt Diesch
  7.                 Applied Micro Systems Technology
  8.                 PO Box 1596, Welch Ave. Station
  9.                 Ames, Iowa  50010
  10.                 (515) 292-0426   CIS [71121,1404]
  11.                 Member - Association of Shareware Professionals
  12.  
  13.    Created:      4/08/1988  (for TP4)
  14.  
  15.    Revised:     10/28/1988  (for TP5)
  16.                             Added additional compatibility for 3.5" drives
  17.  
  18.  
  19.    Copyright 1988 AMST, all rights reserved.
  20.  
  21.  
  22.  
  23.  
  24.                            PROGRAM LICENSE
  25.  
  26.    Applied  Micro Systems Technology reserves the  COPYRIGHT to  this
  27.    program  and  all   related  materials.  The  user  is  granted  a
  28.    non-exclusive   license to  use  the  program  and  is  encouraged
  29.    to  pay for the program if it is found to be useful.   Payment  of
  30.    the    $5  registration  fee   will  entitle  the  user  to   full
  31.    registration which includes permission to use this program in  the
  32.    user's OWN PERSONAL PROGRAMS.  Programs which use DISK13IO.TPU and
  33.    that are offered to the public either as commercial, shareware, or
  34.    freeware must pay a license fee to  AMST  for use of DISK13IO.TPU.
  35.  
  36.    CONTACT AMST IF YOU PLAN TO USE THIS UNIT FOR COMMERCIAL PURPOSES.
  37.  
  38.    Applied  Micro  Systems  Technology  specifically  disclaims   all
  39.    warranties,  expressed or implied,  including but not limited  to,
  40.    implied   warranties  of  merchantability  and  fitness  for   any
  41.    particular  purpose.   In  no event shall  Applied  Micro  Systems
  42.    Technology  be  liable  for  any  loss  of  profit  or  any  other
  43.    commercial   damage,   including  but  not  limited  to   special,
  44.    incidental, consequential or other damages.
  45.  
  46.  
  47.  
  48.                              PROGRAM USE
  49.  
  50.    DISK13IO.TPU is a Turbo Pascal 5.0 unit designed to allow programmers
  51.    to add disk sector I/O (interrupt $13) routines into their programs.
  52.    The routines in DISK13IO will only operate on floppy disks.  The entire
  53.    unit is self-contained, including advanced error checking and error
  54.    recovery.  Functions available through DISK13IO include:
  55.  
  56.       ResetDrives    ( reset disk drive system after an I/O error )
  57.  
  58.       GetDiskStatus  ( get results of last Int $13 operation )
  59.  
  60.       ReadSectors    ( read absolute disk sectors)
  61.  
  62.       WriteSectors   ( write absolute disk sectors )
  63.  
  64.       VerifySectors  ( verify absolute disk sectors (CRC check) )
  65.  
  66.       FormatDisk     ( format a floppy disk in drive A or B, all disk sizes)
  67.  
  68.  
  69.  
  70.  
  71.    To use the DISK13IO.TPU routines, place the DISK13IO declaration in the
  72.    interface section of your program or unit.  For example, a unit heading
  73.    in your program might appear as follows:
  74.  
  75.       unit DISKTEST;
  76.       interface
  77.       uses Crt,Dos,DISK13IO;
  78.  
  79.  
  80.    The DISK13IO routines occasionally must perform some screen I/O to report
  81.    errors or to indicate the status of the format operation.  DISK13IO will
  82.    automatically save the current window setting, screen contents, and
  83.    cursor location and restore these settings after the screen I/O is done.
  84.    When screen output is necessary, a box will appear in the center of the
  85.    screen.  The foreground and background colors of the output box are
  86.    controlled by a global variable of type byte called "Disk13IOAttr".  This
  87.    variable initially assumes the value of the Turbo variable "TextAttr"
  88.    when your controlling program starts.  (See your Turbo manual for a
  89.    discussion of TextAttr in the section of the Turbo Crt unit).  You can
  90.    change the foreground and background colors of the display window by
  91.    setting Disk13IOAttr in the same way you would change TextAttr.  The
  92.    location of the output window cannot be altered.
  93.  
  94.  
  95.                       ╔════════════════════════╗
  96.                       ║                        ║
  97.                       ║  SAMPLE OUTPUT WINDOW  ║
  98.                       ║                        ║
  99.                       ║                        ║
  100.                       ╚════════════════════════╝
  101.  
  102.  
  103.    The remainder of this documentation describes each of the routines in
  104.    DISK13IO.TPU.  Each routine is descibed with input and output parameters.
  105.    For a complete discussion of these routines, consult a DOS Technical
  106.    Reference manual or a book such as Norton's Programmer's Guide to the
  107.    IBM PC & PS/2.
  108.  
  109.  
  110.    **************************  IMPORTANT  *********************************
  111.  
  112.    IT IS THE RESPONSIBILITY OF THE PROGRAMMER TO ENSURE THAT ALL PARAMETERS
  113.    PASSED TO THE DISK13IO.TPU ROUTINES ARE WITHIN ACCEPTABLE RANGES.  ALSO
  114.    BE SURE YOU DO NOT USE THE WRITESECTORS FUNCTION UNLESS YOU UNDERSTAND
  115.    WHAT YOU ARE DOING.  THE FORMAT DISK ROUTINE WILL CHECK TO MAKE SURE
  116.    THAT YOU SPECIFY DRIVE A OR B AND WILL NOT ALLOW FORMATTING OF ANY OTHER
  117.    DRIVES.  ALL OF THESE ROUTINES WILL ONLY OPERATE ON DRIVES A OR B.
  118.  
  119.    ************************************************************************
  120.  
  121.  
  122.    procedure ResetDrives (Drive:byte);
  123.    -----------------------------------
  124.  
  125.    Input:   Drive : byte     Drive to reset (0=A, 1=B, ...)
  126.                              IBM documentation indicates that this call
  127.                              will reset the entire disk system.  Other
  128.                              references indicate that only the specified
  129.                              drive is reset.
  130.    Output:  none
  131.  
  132.  
  133.  
  134.    function GetDiskStatus : byte;
  135.    ------------------------------
  136.  
  137.    Input:   none
  138.  
  139.    Output:  Returns the error code generated by the last Interrupt $13
  140.             operation.  The DISK13IO routines use this function internally
  141.             to check for errors, and if you call this routine after using
  142.             a DISK13IO routine, you will get the same error code as the
  143.             DISK13IO routine last processed.  If no error occurred, this
  144.             function will return 0.
  145.  
  146.  
  147.  
  148.    function ReadSectors (see below) : boolean;
  149.    -------------------------------------------
  150.  
  151.    Input:   Quiet : boolean  True to suppress error messages
  152.             DType : byte     Drive type (1=360K 5-1/4  2=1.2M 5-1/4 )
  153.                                         (3=720K 3-1/2  4=1.44M 3-1/2)
  154.             Drive : byte     Drive to read from (0=A, 1=B)
  155.             Track : byte     Track number to read (0...)
  156.             Side  : byte     Side to read (0 or 1 for floppy disks)
  157.             SSect : byte     Starting sector to read (1...)
  158.             NSect : byte     Number of sectors to read (1... DO NOT USE 0!)
  159.             var Buffer       Variable to store data (512 bytes/sector read)
  160.  
  161.    Output:  True if operation was successful, otherwise false.  Data read
  162.             from sectors will be contained in Buffer if the operation was
  163.             successful.
  164.  
  165.  
  166.  
  167.    function WriteSectors (see below) : boolean;
  168.    --------------------------------------------
  169.  
  170.    Input:   Quiet : boolean  True to suppress error messages
  171.             DType : byte     Drive type (1=360K 5-1/4  2=1.2M 5-1/4 )
  172.                                         (3=720K 3-1/2  4=1.44M 3-1/2)
  173.             Drive : byte     Drive to write to (0=A, 1=B)
  174.             Track : byte     Track number to write (0...)
  175.             Side  : byte     Side to write (0 or 1 for floppy disks)
  176.             SSect : byte     Starting sector to write (1...)
  177.             NSect : byte     Number of sectors to write (1... DO NOT USE 0!)
  178.             var Buffer       Variable with data (512 bytes/sector to write)
  179.  
  180.    Output:  True if operation was successful, otherwise false.
  181.  
  182.  
  183.  
  184.    function VerifySectors (see below) : boolean;
  185.    ---------------------------------------------
  186.  
  187.    Input:   Quiet : boolean  True to suppress error messages
  188.             DType : byte     Drive type (1=360K 5-1/4  2=1.2M 5-1/4 )
  189.                                         (3=720K 3-1/2  4=1.44M 3-1/2)
  190.             Drive : byte     Drive to verify (0=A, 1=B)
  191.             Track : byte     Track number to verify (0...)
  192.             Side  : byte     Side to verify (0 or 1 for floppy disks)
  193.             SSect : byte     Starting sector to verify (1...)
  194.             NSect : byte     Number of sectors to verify (1... DO NOT USE 0!)
  195.  
  196.    Output:  True if operation was successful, otherwise false.
  197.  
  198.  
  199.  
  200.    function FormatDisk (see below) : boolean;
  201.    ------------------------------------------
  202.  
  203.    Input:   DType  : byte        Drive type (1=360K 5-1/4  2=1.2M 5-1/4 )
  204.                                            (3=720K 3-1/2  4=1.44M 3-1/2)
  205.             Drive  : byte        Drive to format (0=A, 1=B)
  206.             MaxBad : byte        Maximum allowable bad sectors from verify
  207.             VLabel : string[11]  Optional volume label
  208.             Verify : boolean     True forces verify with bad sector marking
  209.             ShowRes: boolean     True shows final format results
  210.  
  211.  
  212.    Output:  True if format operation was successful, otherwise false.  As
  213.             the format process takes place, a text window will appear as
  214.             shown below to indicate the progress of the disk format.  If
  215.             the Verify option is on, FormatDisk will mark bad sectors on
  216.             the disk.  Unlike DOS FORMAT, FormatDisk only marks the bad
  217.             sectors, not a whole track at a time.
  218.  
  219.                       ╔═════════════════════════╗
  220.                       ║   AMST DISK FORMATTER   ║
  221.                       ║                         ║
  222.                       ║   Formatting Track xx   ║
  223.                       ║                         ║
  224.                       ╚═════════════════════════╝
  225.  
  226.                    alternating with (if Verify=True)
  227.  
  228.                       ╔═════════════════════════╗
  229.                       ║   AMST DISK FORMATTER   ║
  230.                       ║                         ║
  231.                       ║   Verifying Track  xx   ║
  232.                       ║       Bad Sectors xxx   ║
  233.                       ╚═════════════════════════╝
  234.  
  235.                                  then
  236.  
  237.                       ╔═════════════════════════╗
  238.                       ║   AMST DISK FORMATTER   ║
  239.                       ║                         ║
  240.                       ║   Writing FAT info...   ║
  241.                       ║                         ║
  242.                       ╚═════════════════════════╝
  243.  
  244.                      and finally (if ShowRes=True)
  245.  
  246.                       ╔═════════════════════════╗
  247.                       ║ xxxxxxx bytes total     ║
  248.                       ║ xxxxxxx marked as bad   ║
  249.                       ║ xxxxxxx bytes available ║
  250.                       ║ **** press any key **** ║
  251.                       ╚═════════════════════════╝
  252.  
  253.  
  254.    Following is an short program to demonstrate how you to use DISK13IO.TPU
  255.    in your programs to format a disk.
  256.  
  257.    (AUTHOR'S NOTE: I don't really program this way!!!).
  258.  
  259.  
  260.    {=================== EXAMPLE DISK FORMAT PROGRAM =======================}
  261.  
  262.    Program DiskFormat;
  263.    Uses Crt,Dos,DISK13IO;
  264.    const
  265.      CR  = #13;
  266.      ESC = #27;
  267.    var
  268.      DriveNumber,
  269.      DriveType    : byte;
  270.      UserChoice   : char;
  271.    begin
  272.      ClrScr;
  273.      Writeln('TEST DISK FORMAT PROGRAM');
  274.      Writeln;
  275.      Write('Enter drive letter (A or B, [Esc] to Exit): ');
  276.      repeat
  277.        UserChoice:=UpCase(Readkey);
  278.        if UserChoice = ESC then Halt;
  279.      until UserChoice in ['A','B'];
  280.      Writeln;
  281.      Writeln;
  282.      DriveNumber := Ord(UserChoice)-65;
  283.      Writeln('  1 = 360K 5-1/4"    3 = 720K  3-1/2"');
  284.      Writeln('  2 = 1.2M 5-1/4"    4 = 1.44M 3-1/2"');
  285.      Writeln;
  286.      Write('Enter drive type ([Esc] to Exit): ');
  287.      repeat
  288.        UserChoice:=Readkey;
  289.        if UserChoice = ESC then Halt;
  290.      until UserChoice in ['1'..'4'];
  291.      DriveType:=Ord(UserChoice)-48;
  292.      Writeln;
  293.      Writeln;
  294.      Write('Insert blank disk in drive ',Chr(DriveNumber+65),
  295.            ' and press [Return] ([Esc] to abort)');
  296.      repeat
  297.        UserChoice:=Readkey;
  298.        if UserChoice = ESC then Halt;
  299.      until UserChoice=CR;
  300.      if FormatDisk(DriveType,DriveNumber,0,'TEST VOLUME',True,True) then ;
  301.    end.
  302.  
  303.    {=======================================================================}
  304.  
  305.  
  306.  
  307.    DISK13IO.TPU will handle all errors as they occur by placing an error
  308.    message on the screen and giving the user the option of retrying the
  309.    operation, or aborting the current operation.  If the user aborts,
  310.    control will be returned to your parent program.  For example:
  311.  
  312.                       ╔═════════════════════════╗
  313.                       ║                         ║
  314.                       ║ Drive not ready         ║
  315.                       ║ A)bort or R)etry        ║
  316.                       ║                         ║
  317.                       ╚═════════════════════════╝
  318.  
  319.    In addition to "A", the [Esc] key also serves to abort after an error.
  320.  
  321.  
  322.  
  323.                          TECHNICAL INFORMATION
  324.  
  325.    DISK13IO.TPU is written entirely in Turbo Pascal 5.0.  There is no
  326.    inline assembly code, and the entire program was written using AMST
  327.    developed routines.  I use these routines in many of my programs,
  328.    (custom, shareware, and personal).  The entire unit is self-contained
  329.    and does not rely on any other units (except Crt and DOS in the Turbo
  330.    library).
  331.  
  332.    DISK13IO.TPU has been tested on the following equipment:
  333.  
  334.        AMT-286 with one 360K and one 1.44M drive
  335.        AMT-286 with one 1.2M drive
  336.        Zenith Z-248 with one 360K and one 1.2M drive
  337.        Zenith Z-159 with one 360K drive
  338.        Zenith Z-183 with one 720K drive
  339.        Zenith Z-181 with two 720K drives
  340.  
  341.    If you have any problems with the program, call or write AMST with
  342.    a description of the problem.
  343.  
  344.  
  345.  
  346.    Kurt Diesch
  347.    Friday, October 28, 1988
  348.    11:30 a.m.
  349.    Ames, Iowa
  350.    Copyright 1988, All rights reserved.
  351.